package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dk.model.ProcedureSequence;
import com.dk.mapper.ProcedureSequenceMapper;
import com.dk.service.ProcedureSequenceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dk.vo.ProcedureSequenceVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类  工序顺序
 * </p>
 *
 * @author wbh
 * @since 2023-03-20
 */
@Service
public class ProcedureSequenceServiceImpl extends ServiceImpl<ProcedureSequenceMapper, ProcedureSequence> implements ProcedureSequenceService {
    @Resource
    private ProcedureSequenceMapper procedureSequenceMapper;

    @Override
    public List<ProcedureSequenceVO> getInfoList(String procedureId) {
        //通过procedureId查询,并根据procedure_sequence进行排序
        LambdaQueryWrapper<ProcedureSequence> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(ProcedureSequence::getProcedureSequence);
        wrapper.eq(ProcedureSequence :: getProcedureId,procedureId);
        List<ProcedureSequenceVO> collect = procedureSequenceMapper.selectList(wrapper).stream().map(procedureSequence -> {
            ProcedureSequenceVO vo = new ProcedureSequenceVO();
            BeanUtils.copyProperties(procedureSequence, vo);
            return vo;
        }).collect(Collectors.toList());
        return collect;
    }

    @Override
    public void insertInfoProcedureSequence(ProcedureSequenceVO procedureSequenceVO) {
        ProcedureSequence procedureSequence = new ProcedureSequence();
        BeanUtils.copyProperties(procedureSequenceVO,procedureSequence);
        procedureSequenceMapper.insert(procedureSequence);
    }

    @Override
    public ProcedureSequenceVO getInfoProcedureSequenceById(Integer id) {
        ProcedureSequence procedureSequence = procedureSequenceMapper.selectById(id);
        ProcedureSequenceVO procedureSequenceVO = new ProcedureSequenceVO();
        BeanUtils.copyProperties(procedureSequence,procedureSequenceVO);
        return procedureSequenceVO;
    }

    @Override
    public void updateInfoProcedureSequenceById(ProcedureSequenceVO procedureSequenceVO) {
        ProcedureSequence procedureSequence = new ProcedureSequence();
        BeanUtils.copyProperties(procedureSequenceVO,procedureSequence);
        procedureSequenceMapper.updateById(procedureSequence);
    }

    @Override
    public void deleteInfoProcedureSequenceById(Integer id) {
        procedureSequenceMapper.deleteById(id);
    }
}
